#!/usr/bin/make -f
# Netify Agent Debian Makefile Rules
# Copyright (C) 2016-2020 eGloo, Incorporated
#
# This is free software, licensed under the GNU General Public License v3.
#
# XXX: Fix tabs when necessary:
#	$ sed 's/ \+ /\t/g' -i deploy/debian/debian.rules.in

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Compiler options
CFLAGS=-g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS+=-O0
else
CFLAGS+=-O2
endif

# Build destination directory
export DESTDIR=/usr/src/packages/BUILD/debian/@PACKAGE_TARNAME@

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir

	./autogen.sh
	dh_auto_configure -- --enable-minimal
	dh_auto_build

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	dh_auto_install

	rm -rf $(DESTDIR)@bindir@
	rm -rf $(DESTDIR)@includedir@
	rm -rf $(DESTDIR)@libdir@/*/*.a
	rm -rf $(DESTDIR)@libdir@/*/*.la
	rm -rf $(DESTDIR)@libdir@/*/libndpi*
	rm -rf $(DESTDIR)@libdir@/*/pkgconfig

	install -d -m 0755 $(DESTDIR)@volatilestatedir@
	install -d -m 0755 $(DESTDIR)@sysconfdir@/netify.d

	chmod a+x $(DESTDIR)@datadir@/*.sh

	dh_systemd_enable

	install -D -m 0755 deploy/debian/debian.init \
		$(DESTDIR)@sysconfdir@/init.d/@PACKAGE_TARNAME@

	dh_systemd_start

	install -D -m 0644 deploy/@PACKAGE_TARNAME@.default \
		$(DESTDIR)@sysconfdir@/default/@PACKAGE_TARNAME@

# Build architecture-independent files here.
binary-indep: build install
	# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build binary-indep binary-arch binary install
